package com.nononsenseapps.feeder.net.obs

import com.gitee.wsl.jvm.net.server.HttpCallHandlerFactory
import com.gitee.wsl.jvm.net.server.IHTTPSession
import com.gitee.wsl.prop.BooleanProp.Companion.of
import com.gitee.wsl.prop.Prop
import com.gitee.wsl.prop.StringProp
import com.gitee.wsl.prop.StringProp.Companion.of

object ActiveHandler {
    const val PATH = "/active"

    class Get : ObsDefaultHandler() {
        override val bodyMineType: String
            get() = "text/markdown"

        override fun getText(session: IHTTPSession): String {
            return """
                # This is my document
                
                something else here
                """.trimIndent()
        }

        companion object{
            val Factory = HttpCallHandlerFactory{ Get() }
        }
    }

    class Put : ObsDefaultOperateHandler() {
        override fun getText(session: IHTTPSession): String {
            return ""
        }
        companion object{
            val Factory = HttpCallHandlerFactory{ Put() }
        }
    }

    class Post : ObsDefaultOperateHandler() {
        override fun getText(session: IHTTPSession): String {
            return ""
        }

        companion object{
            val Factory = HttpCallHandlerFactory{ Post() }
        }
    }

    class Delete : ObsDefaultOperateHandler() {
        override val bodyMineType: String
            get() = ""

        override fun getText(session: IHTTPSession): String {
            return ""
        }

        companion object{
            val Factory = HttpCallHandlerFactory{ Delete() }
        }
    }

    class Patch : ObsDefaultHandler() {
        override fun initProps(session: IHTTPSession, urlParams: Map<String, String>) {
            super.initProps(session, urlParams)
            initPropValue(session.headers, heading, position, headingBoundary)
        }

        override val bodyMineType: String
            get() = "text/markdown"

        override fun getText(session: IHTTPSession): String {
            return """# This is my document

                something else here"""
        }

        companion object {
            var heading: Prop<String> = StringProp.of("Heading")
            var position: Prop<String> = StringProp.of("Content-Insertion-Position")
            var headingBoundary: Prop<String> = of("Heading-Boundary", "::")

            val Factory = HttpCallHandlerFactory{ Patch() }

        }
    }

    class Open : ObsDefaultOperateHandler() {
        override fun initProps(session: IHTTPSession, urlParams: Map<String, String>) {
            super.initProps(session, urlParams)
            initPropValue(urlParams, filename)
            initPropValue(session.query, newLeaf)
        }

        override fun getText(session: IHTTPSession): String {
            return ""
        }

        companion object {
            const val PATH = "/open/:filename"
            val filename: Prop<String> = StringProp.of("filename")
            val newLeaf: Prop<Boolean> = of("newLeaf", false)

            val Factory = HttpCallHandlerFactory{ Open() }

        }
    }
}
